/*
 * table_InitializerList.c
 *
 *  Created on: 2012-5-14
 *      Author: guanxiaoying
 */

#include "../../parser/coredef.h"

#define TableSize  (sizeof(INITIALIZERLIST))
#define TableType  PINITIALIZERLIST
#define stTable stInitializerManager.memoryBlocks
#define maxTable stInitializerManager.maxRecordNum
#define  maxNumPerBlk  (stInitializerManager.astMaxNum_Block)
typedef struct _INITIALIZERLIST
{
	U2		usParentKind;		/* 2 */
	U2		usKind;	/* 3 */
	UCHAR   bIllegal;
	SCHAR      constFlg;
	union{
		AST		astInitialList;
		AST		astExpressionInfo;
	}unInitialValue;			/* 4 */

	AST		astDesignation;	/* 5 */
	AST		astNext;		/* 6 */
	AST		astParent;	/* 7 */
	AST		astCodeScp;	/* 7 */
} INITIALIZERLIST, *PINITIALIZERLIST;

/* get the object */
static TABLEMANAGER stInitializerManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stInitializerManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stInitializerManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stInitializerManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stInitializerManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stInitializerManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
static U2 getParentKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usParentKind;
}
static U2 setParentKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usParentKind = value;
}
//ACCESS_U2_FIELD   parameterKind;
static U2 getParamKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind;
}
static U2 setParamKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind = value;
}
//ACCESS_IDX_FIELD  expressionList;
static AST getExpList( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != KIND_INITIALEXPLIST ){
		return 0;
	}
	return pTbl->unInitialValue.astInitialList;
}
static AST setExpList( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != KIND_INITIALEXPLIST ){
		Throw_MemoryError( &stInitializerManager, DATA_SETTING_MISS, index, pTbl->usKind  );
	}
	pTbl->usKind = KIND_INITIALEXPLIST;
	return pTbl->unInitialValue.astInitialList = value;
}
//ACCESS_IDX_FIELD  expression;
static AST getExp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != KIND_EXPRESSIONINFO ){

		return 0;
	}
	return pTbl->unInitialValue.astExpressionInfo;
}
static AST setExp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != KIND_EXPRESSIONINFO ){
		Throw_MemoryError( &stInitializerManager, DATA_SETTING_MISS, index, pTbl->usKind  );
	}
	pTbl->usKind = KIND_EXPRESSIONINFO;
	return pTbl->unInitialValue.astExpressionInfo = value;
}
//ACCESS_IDX_FIELD  next;
static AST getNext( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext;
}
static AST setNext( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext = value;
}
//ACCESS_IDX_FIELD  parent;
static AST getParent( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent;
}
static AST setParent( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent = value;
}
//ACCESS_IDX_FIELD  codeScp;
static AST getCodeScp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astCodeScp;
}
static AST setCodeScp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astCodeScp = value;
}
static BOOL isIllegal( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bIllegal ;
}
static BOOL setIllegal( AST index, BOOL value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bIllegal = value ;
}
static S2 getConstFlg( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->constFlg ;
}
static S2 setConstFlg( AST index, S2 value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->constFlg = value ;
}
static AST getDesignation( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDesignation ;
}
static AST setDesignation( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDesignation = value ;
}
const EXPRESSIONLISTACCESS stExpressionListAccess = {
		ClearTable,
		ResetTable,
		AllocTable,
		getMaxLineNum,
		{
				isIllegal,
				setIllegal
		},
		{
				getConstFlg,
				setConstFlg
		},
		{
				getParentKind,
				setParentKind
		},
		{
				getParamKind,
				setParamKind
		},
		{
				getExpList,
				setExpList
		},
		{
				getExp,
				setExp
		},
		{
				getNext,
				setNext
		},
		{
				getParent,
				setParent
		},
		{
				getCodeScp,
				setCodeScp
		},
		{
				getDesignation,
				setDesignation
		}
};
